<%@page import="GetData.CharsetFilter"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Calendar"%>
<%@page import="dktc_ws.Namhoc" %>
<%@page import="dktc_ws.Monhoc" %>
<%@page import="dktc_ws.Hocky" %>
<%@page import="dktc_ws.Giangvien" %>
<%@page import="GetData.DataWS" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
 request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html; charset=UTF-8"); 
    CharsetFilter ab=new CharsetFilter();
    
    DataWS a = new DataWS();
    List<Namhoc> dsnh = a.laydanhsachnamhoc(-1);
    List<Monhoc> dsmh = a.laydanhsachmonhoc("");
    List<Hocky> dshk = a.laydanhsachhocky(-1);
    List<Giangvien> dsgv = a.laydanhsachgiangvien(-1);
%>

<script>
    var thu = 2;
    var ca = 12;
    var mahk = <%=dshk.get(0).getMahk()%>;
    var xmlhttp;
    
    function setThu(_thu)
    {
        thu = _thu;
        loadPhong();
    }
    
    function setCa(_ca)
    {
        ca = _ca;
        loadPhong();
    }

    function setMaHK(_mahk)
    {
        mahk = _mahk;
        loadPhong();
    }

    function loadPhong()
    {
        if (thu != -1 && ca != -1)
            {
                    if (window.XMLHttpRequest)
                      {// code for IE7+, Firefox, Chrome, Opera, Safari
                      xmlhttp=new XMLHttpRequest();
                      }
                    else
                      {// code for IE6, IE5
                      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                      }
                    xmlhttp.onreadystatechange=function()
                      {
                      if (xmlhttp.readyState==4 && xmlhttp.status==200)
                        {
                            document.getElementById("phonghoc").innerHTML=xmlhttp.responseText;
                        }
                      }
                    xmlhttp.open("GET","class/findRoom.jsp?thu="+thu + "&ca="+ca + "&mahk="+mahk,true);
                    xmlhttp.send();
            }
    }
    
$(document).ready(function(){
    loadPhong();
});
    
</script>

<h1>THÊM LỚP HỌC</h1>



<form action="class/add_class_post.jsp" method="post" onload="loadPhong()">
    <table>
        <tr> 
            <td>MÔN HỌC</td>
            <td><select name="mamonhoc">
            <%
                Monhoc item;
                for (int i=0; i< dsmh.size(); i++)
                {
                    item = dsmh.get(i);
            %>
            <option value="<%=item.getMamh()%>"><%=item.getTenmh()%></option>
            <%
                }
            %>
            </td>
        </select>
        </tr>
        <tr> 
            <td>HỌC KỲ:</td><td> 
                <select name="mahocky" onchange="setMaHK(this.value)">
            <% 
                Namhoc nh;
                for (int i=0;i<dshk.size();i++)
                               {
                %>
                <option value="<%= dshk.get(i).getMahk()%>">
                    <%
                        dsnh = a.laydanhsachnamhoc(dshk.get(i).getManamhoc());
                        nh = dsnh.get(0);
                        String output = "Học kỳ " + dshk.get(i).getTenhk() + " Năm học " + nh.getNam1() + " - " + nh.getNam2();
                        out.print(output);
                    %>
                </option>
                <%
                               }
                %>
        </select>
            </td>
        </tr>
        <tr>
            <td>Giảng viên</td>
            <td><select name="magiangvien">
            <%
                Giangvien gv;
                for (int i=0; i< dsgv.size(); i++)
                {
                    gv = dsgv.get(i);
            %>
            <option value="<%=gv.getMagv()%>"><%=gv.getHocviHocham() + " " + gv.getHotengv()%></option>
            <%
                }
            %>
            </td>
        </tr>
        <tr> 
            <td>Thứ </td>
            <td>
                <select name="thu"  onchange="setThu(this.value)">
                    <% for (int i=2;i<=7;i++)
                        {
                    %>
                        <option value="<%=i%>">Thứ <%=i%></option>
                    <%
                        }
                    %>
                </select>
            </td>
        </tr>
        <tr> 
            <td>Ca </td>
            <td>
                <select name="ca"  onchange="setCa(this.value)">
                     <option value="12">Sáng (ca 1,2)</option>
                     <option value="34">Chiều (ca 3,4)</option>
                </select>
            </td>
            <tr>
                <td>
                    Phòng:
                </td>
                
                <td>
                    <select id="phonghoc" name="sophong">
                    </select>

                </td>
            </tr>
        </tr>
        <tr>
            <td>Sỉ số tối đa</td>
            <td>
                <input type="text" name="sisotoida"/>
            </td>
        </tr>
        
    <tr> 
            <td></td><td>  <input type="submit" name="addclass" value="Thêm Lớp"></input></td>
        </tr>
   
    </table>
</form>